// pages/xinxi/xinxi.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow:true,
    name:'',
    grade:'',
    lou: '',
    ss: "",
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      user_id: wx.getStorageSync('userid'),
      password: wx.getStorageSync('password'),
      name:wx.getStorageSync('name'),
      grade:wx.getStorageSync('class'),
      lou: wx.getStorageSync('lou'),
      ss: wx.getStorageSync('ss')
    })
  },
  revamp:function(e){
    this.setData({
      isshow:false,
    })
  },
  cancel:function(e){
    this.setData({
      isshow:true,
      lou: wx.getStorageSync('lou'),
      ss: wx.getStorageSync('ss')
    })
  },
  chlou: function (e) {
    // console.log(e.detail)
    this.setData({
      lou: e.detail
    })
  },
  chss: function (e) {
    // console.log(e.detail)
    this.setData({
      ss: e.detail
    })
  },
  amend: function (e) {
    var that = this
    var user_id = wx.getStorageSync('userid')
    var password = wx.getStorageSync('password')
    var lou=wx.getStorageSync('lou')
    var ss=wx.getStorageSync('ss')
    if(lou==that.data.lou && ss==that.data.ss){
      wx.showModal({
        title: '提示',
        content: '请输入修改内容',
      })
    }else{
    wx.request({
      url: app.globalData.URL + '/dormitory_repair/modify_dormitory_info',
      method: "POST",
      data: {
        user_id,
        password,
        dormitory: that.data.lou,
        room: that.data.ss
      },
      success(res) {
        wx.showToast({
          title: '修改成功',
        })
        // console.log(res)
        wx.setStorageSync("lou", that.data.lou);
        wx.setStorageSync("ss", that.data.ss);
        that.setData({
          isshow:true
        })
      },
      fail(err) {
        console.log(err)
      },
    })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})